package com.tl.bootmeter.mapper;

import com.tl.bootmeter.pojo.District;
import com.tl.bootmeter.pojo.DistrictStationResult;
import com.tl.bootmeter.pojo.Station;
import com.tl.bootmeter.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {

    //登陆
    @Select("select * from user where uname =#{param1} and upass=#{param2}")
    User selectUser(String uname, String upass);

    //根据邀请码查询一个用户
    User selectUserByCDK(String ucdkey);
    //查询所有管区
    @Select("select * from district")
    List<District> selectAllDistrict();
    //根据用户等级查询管区，站信息
    @Select("select dt.district_name,s.station_id,s.station_name\n" +
            "\t\tfrom user_district_stand uds right join district dt on uds.district_id = dt.district_id right join station s on uds.station_id = s.station_id\n" +
            "\t\twhere uds.ulevel=#{ulevel}")
    DistrictStationResult selectUserByEvelDiSR(String ulevel);
    //根据用户等级查询管区信息
    @Select("select uds.ulevel,dt.district_id,dt.district_name\n" +
            "\t\tfrom user_district_stand uds RIGHT JOIN district dt ON uds.district_id = dt.district_id \n" +
            "\t\twhere uds.ulevel=#{ulevel}")
    District selectUserByEvelDistrict(String ulevel);
    //查询这个管区下一共有多少站
    @Select("select s.station_id,s.station_name\n" +
            "\t\tfrom district_station ds RIGHT JOIN district dt ON ds.district_id = dt.district_id RIGHT JOIN station s ON ds.station_id = s.station_id\n" +
            "\t\twhere ds.district_id = #{district_id}")
    List<Station> selectByDistrictIdStation(int district_id);

    //用户注册
    @Insert("insert into user values (#{uid},#{uname},#{upass},#{ugender},#{ulevel},#{uphone},#{unickName})")
    int insertUser(User user);

    //查询账号是否已经存在
    @Select("select * from user where uname = #{uname}")
    User  selectUserByuname(String uname);
}
